package com.iprojectmanager.views;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.iprojectmanager.entities.*;
import com.iprojectmanager.managers.*;

/**
 *
 * @author jons
 */
public class VistaRol extends Vista
{
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
    {
        PrintWriter out = response.getWriter();
        HttpSession user = request.getSession();
        Administrador root = (Administrador)user.getAttribute("user");

            out.println(Utilities.getDocType());
            out.println("<HTML>" + Utilities.getHead("Roles del sistema"));
            out.println("<div id=\"container\">");
            out.println(Utilities.getIntro("Roles",root));

            String form =
                    "<div id=\"pageContent\">"+
                            "<div id=\"selection1\">" + this.getFormRoles(request) + "</div>" +
                            Utilities.getFooter() +
                    "</div>";

            out.println(form);
            out.println(Utilities.getMenu());
            out.println("</div> <!-- fin container---></BODY></HTML>");
    }

    public String getFormRoles(HttpServletRequest request)
    {
        RolManager manager = new RolManager();
        ArrayList<Rol> roles = manager.getRoles();

        String table = "";
            for(Rol rol : roles)
            {
                table +=
                    "<tr>" +
                        "<td><input name=\"rol\" value=\""+ rol.getId() +"\" type=\"checkbox\" size=\"20\"></td>" +
                        "<td>"+ rol.getId() +"</td>"+
                        "<td>"+ rol.getNombre() + "</td>"+
                    "</tr>";
            }

        return
           "<h3><span>Administracion de Roles</span></h3>"+
                "<p class=\"p1\"><span>"+
                    "<form action=\"RolControl\" method=\"GET\">"+
                        "<label>ROLES:</label>"+
                        "<select name=\"roles\">"+
                            table +
                        "</select><br></br>"+
                            "</select><br></br>"+
                         "<button type=\"submit\">Aceptar</button>"+
                    "</form>"+
                "</span></p>";
    }

    @Override
    public String getServletInfo()
    {
        return "Vista Rol de Proyecto";
    }
}